﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RIS.TMP.WEB.APP.Models;
using RIS.TMP.WEB.APP.AddMigrations;

namespace RIS.TMP.WEB.APP.Controllers
{
    public class CFBranchController : Controller
    {
        private AllContext db = new AllContext();

        //
        // GET: /CFBranch/

        public ActionResult Index()
        {
            return View(db.CFBranchs.Where(x => x.RecordStatus == "U").ToList());
        }

        //
        // GET: /CFBranch/Details/5

        public ActionResult Details(int id = 0)
        {
            CFBranch cfbranch = db.CFBranchs.Find(id);
            if (cfbranch == null)
            {
                return HttpNotFound();
            }
            return View(cfbranch);
        }

        //
        // GET: /CFBranch/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /CFBranch/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(CFBranch cfbranch)
        {
            if (ModelState.IsValid)
            {
                cfbranch.RecordStatus = "U";
                cfbranch.CreateBy = Session["LogedId"].ToString();
                cfbranch.CreateWhen = DateTime.Now;
                db.CFBranchs.Add(cfbranch);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(cfbranch);
        }

        //
        // GET: /CFBranch/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CFBranch cfbranch = db.CFBranchs.Find(id);
            if (cfbranch == null)
            {
                return HttpNotFound();
            }
            return View(cfbranch);
        }

        //
        // POST: /CFBranch/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(CFBranch cfbranch)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cfbranch).State = EntityState.Modified;
                cfbranch.UpdateBy = Session["LogedId"].ToString();
                cfbranch.UpdateWhen = DateTime.Now;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(cfbranch);
        }

        //
        // GET: /CFBranch/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CFBranch cfbranch = db.CFBranchs.Find(id);
            if (cfbranch == null)
            {
                return HttpNotFound();
            }
            return View(cfbranch);
        }

        //
        // POST: /CFBranch/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            CFBranch cfbranch = db.CFBranchs.Find(id);
            db.Entry(cfbranch).State = EntityState.Modified;
            cfbranch.RecordStatus = "D";
            cfbranch.UpdateBy = Session["LogedId"].ToString();
            cfbranch.UpdateWhen = DateTime.Now;
            //db.CFBranchs.Remove(cfbranch);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}